import { Action } from "./Action";
import Command from "./Command";

export default class Handler {

    public method: Function;
    public thisArgs: any;
    public args: any[];

    constructor(thisArg: any = null, method: Function = null, args: any[] = null) {
        this.thisArgs = thisArg;
        this.method = method;
        this.args = args;
    }
    // 执行处理
    public execute(): void {
        if(this.method != null) {
            this.method.apply(this.thisArgs,this.args);
        }
    }
    public executeWithCommand(command: Command): void {
        
    }
    // 执行处理
    public executeWith(data: any[]): void {
        if(data == null) {
            this.execute();
        } else {
            if(this.method !== null) {
                this.method.apply(this.thisArgs,this.args ? this.args.concat(data) : data);
            }
        }
    }

}